```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redis内存优化完全指南 | 专业开发者手册</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', 'Noto Serif SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            background-color: #f9fafb;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e48aa 0%, #9d50bb 100%);
        }
        .highlight-card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            border-left: 4px solid #6e48aa;
        }
        .highlight-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .section-divider {
            border-top: 1px dashed #ddd;
            margin: 3rem 0;
        }
        .drop-cap:first-letter {
            float: left;
            font-size: 4rem;
            line-height: 0.8;
            margin: 0.15em 0.1em 0 0;
            color: #6e48aa;
            font-weight: 700;
        }
        .code-block {
            background-color: #2d3748;
            color: #f8fafc;
            border-radius: 0.375rem;
            overflow-x: auto;
        }
        .vis-card {
            background: white;
            border-radius: 0.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            padding: 1.5rem;
            margin-bottom: 2rem;
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold leading-tight mb-4">
                        Redis内存优化完全指南
                    </h1>
                    <p class="text-xl opacity-90 mb-8">
                        释放Redis性能潜力的专业技巧与最佳实践
                    </p>
                    <div class="flex items-center">
                        <span class="bg-white bg-opacity-20 px-3 py-1 rounded-full text-sm mr-3">
                            <i class="fas fa-database mr-1"></i> 数据库优化
                        </span>
                        <span class="bg-white bg-opacity-20 px-3 py-1 rounded-full text-sm">
                            <i class="fas fa-chart-line mr-1"></i> 性能调优
                        </span>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1720576112090-e0bf942c-d77e-43cb-9c36-ac0f469010e8.png" 
                         alt="Redis性能优化" 
                         class="rounded-lg shadow-2xl w-full max-w-md transform hover:scale-105 transition-all duration-300">
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto max-w-5xl px-4 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="drop-cap bg-white p-6 rounded-lg shadow-md">
                <p class="text-lg leading-relaxed">
                    作为一个高性能的内存数据库，Redis广泛应用于各种需要快速数据访问的场景中，比如缓存、会话管理、实时统计等。然而，随着数据量的增长和应用复杂度的提高，Redis的内存使用也会变得越来越紧张。如果不加以合理管理和优化，内存消耗可能会迅速达到服务器的限制，从而影响系统的稳定性和性能。因此，掌握Redis内存优化的技巧，对于保持系统高效稳定运行至关重要。
                </p>
                <p class="text-lg leading-relaxed mt-4">
                    Redis之所以能够提供卓越的性能，很大程度上依赖于其内存操作的高效性。然而，这也意味着我们需要更加关注内存的使用和管理。在实际项目中，我们不仅需要了解Redis的基本操作和使用方法，还要深入理解其内存管理机制，并能根据具体情况进行优化调整。这就需要我们从多个维度来考虑，包括数据结构选择、配置参数调优、数据压缩、持久化策略以及内存监控和管理等。
                </p>
            </div>
        </section>

        <!-- Memory Usage Analysis -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="h-px bg-purple-500 w-8 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800">内存使用分析</h2>
            </div>
            
            <div class="flex flex-col md:flex-row gap-6 mb-8">
                <div class="md:w-1/3">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1720576185286-1e4f0348-203f-404d-8508-316e90c4d748.png" 
                         alt="内存分析" 
                         class="rounded-lg shadow-md w-full h-auto hover:shadow-lg transition-shadow duration-300">
                </div>
                <div class="md:w-2/3">
                    <p class="text-lg mb-6">
                        在进行Redis内存优化时，首先需要对内存使用进行全面而深入的分析。通过内存使用分析，我们可以明确当前Redis实例的内存消耗情况，找出内存使用的热点和潜在问题，从而为后续的优化工作提供指导。
                    </p>
                    
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                        <div class="highlight-card bg-white p-4 rounded-lg shadow-sm">
                            <div class="text-purple-600 mb-2">
                                <i class="fas fa-chart-pie fa-lg"></i>
                            </div>
                            <h3 class="font-semibold text-lg mb-2">内存使用概览</h3>
                            <p class="text-gray-600">
                                使用Redis的内置命令<code class="bg-gray-100 px-1 rounded">INFO MEMORY</code>获取内存使用的概况。
                            </p>
                        </div>
                        
                        <div class="highlight-card bg-white p-4 rounded-lg shadow-sm">
                            <div class="text-purple-600 mb-2">
                                <i class="fas fa-project-diagram fa-lg"></i>
                            </div>
                            <h3 class="font-semibold text-lg mb-2">数据结构内存占用</h3>
                            <p class="text-gray-600">
                                分析各类数据结构的内存使用情况，找到内存消耗较大的数据结构。
                            </p>
                        </div>
                        
                        <div class="highlight-card bg-white p-4 rounded-lg shadow-sm">
                            <div class="text-purple-600 mb-2">
                                <i class="fas fa-key fa-lg"></i>
                            </div>
                            <h3 class="font-semibold text-lg mb-2">大键(Big Key)分析</h3>
                            <p class="text-gray-600">
                                使用<code class="bg-gray-100 px-1 rounded">SCAN</code>命令或<code class="bg-gray-100 px-1 rounded">--bigkeys</code>选项扫描并识别大键。
                            </p>
                        </div>
                        
                        <div class="highlight-card bg-white p-4 rounded-lg shadow-sm">
                            <div class="text-purple-600 mb-2">
                                <i class="fas fa-puzzle-piece fa-lg"></i>
                            </div>
                            <h3 class="font-semibold text-lg mb-2">内存碎片分析</h3>
                            <p class="text-gray-600">
                                通过分析内存碎片率判断内存碎片的严重程度。
                            </p>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Mermaid Visualization -->
            <div class="vis-card mt-8">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">Redis内存分析流程图</h3>
                <div class="mermaid">
                    graph TD
                    A[开始内存分析] --> B[使用INFO MEMORY命令]
                    B --> C[分析数据结构内存]
                    B --> D[识别大键]
                    B --> E[检查内存碎片率]
                    C --> F[优化数据结构]
                    D --> G[拆分大键]
                    E --> H[整理内存碎片]
                    F --> I[内存优化完成]
                    G --> I
                    H --> I
                </div>
            </div>
        </section>

        <!-- Data Structure Optimization -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="h-px bg-purple-500 w-8 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800">数据结构优化</h2>
            </div>
            
            <div class="flex flex-col md:flex-row gap-6 mb-8">
                <div class="md:w-1/3">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1720576288570-46e259f1-b560-4dd1-9b8f-5e546a5e5171.png" 
                         alt="数据结构优化" 
                         class="rounded-lg shadow-md w-full h-auto hover:shadow-lg transition-shadow duration-300">
                </div>
                <div class="md:w-2/3">
                    <p class="text-lg mb-6">
                        在Redis内存优化的过程中，数据结构优化是一个非常重要的环节。不同的数据结构在存储相同数据时，所占用的内存量可能会有显著差异。通过选择合适的数据结构，或者优化现有数据结构的使用方式，可以有效减少内存消耗，提高系统性能。
                    </p>
                    
                    <div class="grid grid-cols-1 gap-6">
                        <div class="bg-white p-5 rounded-lg shadow-sm border-l-4 border-purple-500">
                            <h3 class="font-semibold text-xl mb-3 text-purple-700">字符串(String)</h3>
                            <ul class="list-disc pl-5 space-y-2 text-gray-700">
                                <li><strong>压缩字符串：</strong>对于较长的字符串，可以考虑对其进行压缩存储。</li>
                                <li><strong>合理设置编码方式：</strong>确保字符串长度在合理范围内，可以减少内存开销。</li>
                            </ul>
                        </div>
                        
                        <div class="bg-white p-5 rounded-lg shadow-sm border-l-4 border-blue-500">
                            <h3 class="font-semibold text-xl mb-3 text-blue-700">列表(List)</h3>
                            <ul class="list-disc pl-5 space-y-2 text-gray-700">
                                <li><strong>使用短列表：</strong>对于短列表，Redis会使用紧凑的ziplist编码。</li>
                                <li><strong>合理选择操作：</strong>避免在列表中间进行插入或删除操作。</li>
                            </ul>
                        </div>
                        
                        <div class="bg-white p-5 rounded-lg shadow-sm border-l-4 border-green-500">
                            <h3 class="font-semibold text-xl mb-3 text-green-700">集合(Set)</h3>
                            <ul class="list-disc pl-5 space-y-2 text-gray-700">
                                <li><strong>使用intset编码：</strong>对于只包含整数的短集合，Redis会使用intset编码。</li>
                                <li><strong>避免存储大量大元素：</strong>考虑将其分片存储到多个集合中。</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Data Structure Comparison Table -->
            <div class="vis-card">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">Redis数据结构优化对比</h3>
                <div class="overflow-x-auto">
                    <table class="min-w-full bg-white rounded-lg overflow-hidden">
                        <thead class="bg-gray-100">
                            <tr>
                                <th class="py-3 px-4 text-left font-semibold text-gray-700">数据结构</th>
                                <th class="py-3 px-4 text-left font-semibold text-gray-700">优化策略</th>
                                <th class="py-3 px-4 text-left font-semibold text-gray-700">适用场景</th>
                                <th class="py-3 px-4 text-left font-semibold text-gray-700">内存节省</th>
                            </tr>
                        </thead>
                        <tbody class="divide-y divide-gray-200">
                            <tr>
                                <td class="py-3 px-4">字符串(String)</td>
                                <td class="py-3 px-4">压缩存储、合理编码</td>
                                <td class="py-3 px-4">键值存储、计数器</td>
                                <td class="py-3 px-4">高</td>
                            </tr>
                            <tr class="bg-gray-50">
                                <td class="py-3 px-4">列表(List)</td>
                                <td class="py-3 px-4">使用ziplist、避免中间操作</td>
                                <td class="py-3 px-4">队列、栈、时间线</td>
                                <td class="py-3 px-4">中</td>
                            </tr>
                            <tr>
                                <td class="py-3 px-4">集合(Set)</td>
                                <td class="py-3 px-4">intset编码、分片存储</td>
                                <td class="py-3 px-4">标签、社交关系</td>
                                <td class="py-3 px-4">高</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </section>

        <!-- Memory Management Parameters -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="h-px bg-purple-500 w-8 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800">内存管理参数调优</h2>
            </div>
            
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
                <div class="highlight-card bg-white p-6 rounded-lg">
                    <div class="text-purple-600 text-3xl mb-4">
                        <i class="fas fa-memory"></i>
                    </div>
                    <h3 class="font-semibold text-xl mb-3">内存分配机制</h3>
                    <p class="text-gray-600 mb-4">
                        Redis使用jemalloc作为默认的内存分配器。合理配置jemalloc的参数可以提高内存分配效率，减少内存碎片。
                    </p>
                    <div class="code-block p-4 rounded text-sm">
                        <code class="text-green-400"># 配置jemalloc参数</code><br>
                        <code>jemalloc-bg-thread: yes</code><br>
                        <code>maxmemory: 4gb</code>
                    </div>
                </div>
                
                <div class="highlight-card bg-white p-6 rounded-lg">
                    <div class="text-blue-600 text-3xl mb-4">
                        <i class="fas fa-filter"></i>
                    </div>
                    <h3 class="font-semibold text-xl mb-3">内存淘汰策略</h3>
                    <p class="text-gray-600 mb-4">
                        当Redis实例的内存使用达到maxmemory限制时，Redis会根据配置的淘汰策略来释放内存。
                    </p>
                    <ul class="list-disc pl-5 space-y-1 text-gray-700">
                        <li>allkeys-lru: 淘汰最近最少使用的键</li>
                        <li>volatile-ttl: 淘汰最近过期的键</li>
                        <li>noeviction: 不淘汰，直接返回错误</li>
                    </ul>
                </div>
                
                <div class="highlight-card bg-white p-6 rounded-lg">
                    <div class="text-red-600 text-3xl mb-4">
                        <i class="fas fa-puzzle-piece"></i>
                    </div>
                    <h3 class="font-semibold text-xl mb-3">内存碎片管理</h3>
                    <p class="text-gray-600 mb-4">
                        通过合理配置内存碎片管理参数，可以减少内存碎片，提高内存利用率。
                    </p>
                    <div class="code-block p-4 rounded text-sm">
                        <code class="text-green-400"># 主动碎片整理配置</code><br>
                        <code>activedefrag: yes</code><br>
                        <code>activedefrag-cycle-min: 5</code><br>
                        <code>activedefrag-cycle-max: 75</code>
                    </div>
                </div>
            </div>
            
            <!-- Mermaid Visualization for Memory Management -->
            <div class="vis-card">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">内存管理策略决策图</h3>
                <div class="mermaid">
                    graph LR
                    A[内存不足?] -->|是| B[配置maxmemory]
                    B --> C[选择淘汰策略]
                    C --> D[allkeys-lru]
                    C --> E[volatile-lru]
                    C --> F[volatile-ttl]
                    A -->|否| G[监控内存使用]
                    G --> H[分析内存碎片]
                    H --> I[配置activedefrag]
                </div>
            </div>
        </section>

        <!-- Data Compression -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="h-px bg-purple-500 w-8 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800">数据压缩</h2>
            </div>
            
            <div class="bg-white rounded-lg shadow-md overflow-hidden mb-8">
                <div class="md:flex">
                    <div class="md:w-1/3 bg-gray-50 p-6 flex items-center justify-center">
                        <div class="text-center">
                            <div class="text-purple-600 text-5xl mb-4">
                                <i class="fas fa-compress-arrows-alt"></i>
                            </div>
                            <h3 class="font-semibold text-xl">压缩算法对比</h3>
                        </div>
                    </div>
                    <div class="md:w-2/3 p-6">
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <div class="border border-gray-200 rounded-lg p-4">
                                <h4 class="font-semibold text-lg text-blue-600 mb-2">Gzip</h4>
                                <p class="text-gray-600 mb-2">高压缩率，速度较慢</p>
                                <div class="flex items-center text-sm text-gray-500">
                                    <span class="inline-block w-3 h-3 bg-blue-500 rounded-full mr-1"></span>
                                    <span>压缩率: 高</span>
                                </div>
                                <div class="flex items-center text-sm text-gray-500">
                                    <span class="inline-block w-3 h-3 bg-blue-300 rounded-full mr-1"></span>
                                    <span>速度: 慢</span>
                                </div>
                            </div>
                            
                            <div class="border border-gray-200 rounded-lg p-4">
                                <h4 class="font-semibold text-lg text-green-600 mb-2">Snappy</h4>
                                <p class="text-gray-600 mb-2">快速压缩，压缩率较低</p>
                                <div class="flex items-center text-sm text-gray-500">
                                    <span class="inline-block w-3 h-3 bg-green-300 rounded-full mr-1"></span>
                                    <span>压缩率: 中</span>
                                </div>
                                <div class="flex items-center text-sm text-gray-500">
                                    <span class="inline-block w-3 h-3 bg-green-500 rounded-full mr-1"></span>
                                    <span>速度: 快</span>
                                </div>
                            </div>
                            
                            <div class="border border-gray-200 rounded-lg p-4">
                                <h4 class="font-semibold text-lg text-purple-600 mb-2">LZ4</h4>
                                <p class="text-gray-600 mb-2">快速压缩，中高压缩率</p>
                                <div class="flex items-center text-sm text-gray-500">
                                    <span class="inline-block w-3 h-3 bg-purple-500 rounded-full mr-1"></span>
                                    <span>压缩率: 中高</span>
                                </div>
                                <div class="flex items-center text-sm text-gray-500">
                                    <span class="inline-block w-3 h-3 bg-purple-400 rounded-full mr-1"></span>
                                    <span>速度: 非常快</span>
                                </div>
                            </div>
                            
                            <div class="border border-gray-200 rounded-lg p-4">
                                <h4 class="font-semibold text-lg text-red-600 mb-2">Zstd</h4>
                                <p class="text-gray-600 mb-2">高压缩率，快速压缩</p>
                                <div class="flex items-center text-sm text-gray-500">
                                    <span class="inline-block w-3 h-3 bg-red-500 rounded-full mr-1"></span>
                                    <span>压缩率: 高</span>
                                </div>
                                <div class="flex items-center text-sm text-gray-500">
                                    <span class="inline-block w-3 h-3 bg-red-400 rounded-full mr-1"></span>
                                    <span>速度: 快</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div>
                    <h3 class="font-semibold text-xl mb-3 text-gray-800">实现方式</h3>
                    <div class="code-block p-4 rounded text-sm mb-4">
                        <code class="text-green-400">// 使用Snappy进行数据压缩</code><br>
                        <code>byte[] compressedData = Snappy.compress(originalData);</code><br>
                        <code>jedis.set("key", compressedData);</code><br><br>
                        <code class="text-green-400">// 数据解压</code><br>
                        <code>byte[] compressedData = jedis.get("key");</code><br>
                        <code>byte[] originalData = Snappy.uncompress(compressedData);</code>
                    </div>
                </div>
                
                <div>
                    <h3 class="font-semibold text-xl mb-3 text-gray-800">优势与挑战</h3>
                    <div class="bg-white p-4 rounded-lg shadow-sm">
                        <div class="flex items-start mb-3">
                            <div class="text-green-500 mr-3 mt-1">
                                <i class="fas fa-check-circle"></i>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800">优势</h4>
                                <ul class="list-disc pl-5 text-gray-600 text-sm">
                                    <li>减少内存占用</li>
                                    <li>提高网络传输效率</li>
                                    <li>扩展性强</li>
                                </ul>
                            </div>
                        </div>
                        
                        <div class="flex items-start">
                            <div class="text-red-500 mr-3 mt-1">
                                <i class="fas fa-exclamation-triangle"></i>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800">挑战</h4>
                                <ul class="list-disc pl-5 text-gray-600 text-sm">
                                    <li>增加CPU负载</li>
                                    <li>复杂性增加</li>
                                    <li>兼容性问题</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Hot and Cold Data Separation -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="h-px bg-purple-500 w-8 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800">热数据与冷数据分离</h2>
            </div>
            
            <div class="flex flex-col md:flex-row gap-6 mb-8">
                <div class="md:w-1/2">
                    <div class="bg-white p-6 rounded-lg shadow-sm mb-6">
                        <h3 class="font-semibold text-xl mb-4 text-purple-700">热数据</h3>
                        <div class="flex items-start">
                            <div class="text-red-500 text-2xl mr-4">
                                <i class="fas fa-fire"></i>
                            </div>
                            <div>
                                <p class="text-gray-700 mb-3">
                                    高频访问的数据，通常是用户频繁请求或系统频繁读取和更新的数据。
                                </p>
                                <ul class="list-disc pl-5 text-gray-600">
                                    <li>存储在高性能存储介质中</li>
                                    <li>确保快速读写速度和低延迟</li>
                                    <li>使用LRU/LFU策略管理</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    
                    <div class="code-block p-4 rounded text-sm">
                        <code class="text-green-400">// 热数据存储在Redis中</code><br>
                        <code>if (isHotData(key)) {</code><br>
                        <code>&nbsp;&nbsp;redis.set(key, value);</code><br>
                        <code>} else {</code><br>
                        <code>&nbsp;&nbsp;database.save(key, value);</code><br>
                        <code>}</code>
                    </div>
                </div>
                
                <div class="md:w-1/2">
                    <div class="bg-white p-6 rounded-lg shadow-sm mb-6">
                        <h3 class="font-semibold text-xl mb-4 text-blue-700">冷数据</h3>
                        <div class="flex items-start">
                            <div class="text-blue-500 text-2xl mr-4">
                                <i class="fas fa-snowflake"></i>
                            </div>
                            <div>
                                <p class="text-gray-700 mb-3">
                                    低频访问的数据，通常是历史数据、归档数据或不常使用的数据。
                                </p>
                                <ul class="list-disc pl-5 text-gray-600">
                                    <li>存储在低速存储介质中</li>
                                    <li>节省资源和成本</li>
                                    <li>可定期归档</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    
                    <div class="code-block p-4 rounded text-sm">
                        <code class="text-green-400">// 冷数据迁移到数据库</code><br>
                        <code>List&lt;String&gt; coldDataKeys = getColdDataKeys();</code><br>
                        <code>for (String key : coldDataKeys) {</code><br>
                        <code>&nbsp;&nbsp;String value = redis.get(key);</code><br>
                        <code>&nbsp;&nbsp;database.save(key, value);</code><br>
                        <code>&nbsp;&nbsp;redis.del(key);</code><br>
                        <code>}</code>
                    </div>
                </div>
            </div>
            
            <!-- Mermaid Visualization for Hot/Cold Data -->
            <div class="vis-card">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">热冷数据分离流程图</h3>
                <div class="mermaid">
                    graph TB
                    A[数据访问] --> B{访问频率高?}
                    B -->|是| C[标记为热数据]
                    C --> D[存储在Redis内存中]
                    B -->|否| E[标记为冷数据]
                    E --> F[存储到数据库/磁盘]
                    G[定期监控] --> H[调整热冷数据分类]
                </div>
            </div>
        </section>

        <!-- Regular Cleanup and Expired Data -->
        <section>
            <div class="flex items-center mb-6">
                <div class="h-px bg-purple-500 w-8 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800">定期清理和过期数据处理</h2>
            </div>
            
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
                <div class="highlight-card bg-white p-6 rounded-lg">
                    <div class="text-purple-600 text-3xl mb-4">
                        <i class="fas fa-clock"></i>
                    </div>
                    <h3 class="font-semibold text-xl mb-3">定时删除</h3>
                    <p class="text-gray-600 mb-4">
                        为每个键设置过期时间，当时间到达时，Redis会自动删除该键。
                    </p>
                    <div class="code-block p-4 rounded text-sm">
                        <code>redis.expire("key", 60);</code><br>
                        <code>redis.setex("key", 60, "value");</code>
                    </div>
                </div>
                
                <div class="highlight-card bg-white p-6 rounded-lg">
                    <div class="text-blue-600 text-3xl mb-4">
                        <i class="fas fa-broom"></i>
                    </div>
                    <h3 class="font-semibold text-xl mb-3">惰性删除</h3>
                    <p class="text-gray-600 mb-4">
                        当客户端访问某个键时，Redis检查该键是否过期，如果过期则删除。
                    </p>
                    <div class="code-block p-4 rounded text-sm">
                        <code class="text-green-400"># 配置惰性删除</code><br>
                        <code>lazyfree-lazy-expire: yes</code>
                    </div>
                </div>
                
                <div class="highlight-card bg-white p-6 rounded-lg">
                    <div class="text-green-600 text-3xl mb-4">
                        <i class="fas fa-calendar-alt"></i>
                    </div>
                    <h3 class="font-semibold text-xl mb-3">定期删除</h3>
                    <p class="text-gray-600 mb-4">
                        Redis定期随机抽取一部分键进行过期检查和删除操作。
                    </div>
                    <div class="code-block p-4 rounded text-sm">
                        <code class="text-green-400"># 配置定期删除频率</code><br>
                        <code>hz: 10</code><br>
                        <code>active-expire-cycles: 20</code>
                    </div>
                </div>
            </div>
            
            <div class="vis-card">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">过期数据处理策略对比</h3>
                <div class="overflow-x-auto">
                    <table class="min-w-full bg-white rounded-lg overflow-hidden">
                        <thead class="bg-gray-100">
                            <tr>
                                <th class="py-3 px-4 text-left font-semibold text-gray-700">策略</th>
                                <th class="py-3 px-4 text-left font-semibold text-gray-700">优点</th>
                                <th class="py-3 px-4 text-left font-semibold text-gray-700">缺点</th>
                                <th class="py-3 px-4 text-left font-semibold text-gray-700">适用场景</th>
                            </tr>
                        </thead>
                        <tbody class="divide-y divide-gray-200">
                            <tr>
                                <td class="py-3 px-4">定时删除</td>
                                <td class="py-3 px-4">及时清理</td>
                                <td class="py-3 px-4">CPU开销大</td>
                                <td class="py-3 px-4">时效性要求高</td>
                            </tr>
                            <tr class="bg-gray-50">
                                <td class="py-3 px-4">惰性删除</td>
                                <td class="py-3 px-4">CPU开销小</td>
                                <td class="py-3 px-4">内存不能及时释放</td>
                                <td class="py-3 px-4">内存充足场景</td>
                            </tr>
                            <tr>
                                <td class="py-3 px-4">定期删除</td>
                                <td class="py-3 px-4">平衡性能与内存</td>
                                <td class="py-3 px-4">需要合理配置</td>
                                <td class="py-3 px-4">大多数场景</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </section>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            mermaid.initialize({
                startOnLoad: true,
                theme: 'default',
                flowchart: {
                    useMaxWidth: true,
                    htmlLabels: true,
                    curve: 'basis'
                }
            });
            
            // 添加卡片悬停效果
            document.querySelectorAll('.highlight-card').forEach(card => {
                card.addEventListener('mouseenter', function() {
                    this.style.boxShadow = '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)';
                });
                card.addEventListener('mouseleave', function() {
                    this.style.boxShadow = '';
                });
            });
        });
    </script>
</body>
</html>
```